﻿using ATEDiagnoser;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ATECapybara
{
    public partial class ST_BluetoothShow : Form
    {
        public ST_BluetoothShow()
        {
            InitializeComponent();
        }


        /// <summary>
        /// 蓝牙地址生成、自动复制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void st_bluetooth_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string temp = st_bluetooth.Text.Trim();
                if (st_bluetooth_lower.Checked)
                {
                    temp = temp.ToLower();
                }
                if (st_bluetooth_segmentation.Checked)
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < temp.Length; i++)
                    {
                        sb.Append(temp[i]);
                        i++;
                        if (i < temp.Length)
                        {
                            sb.Append(temp[i]);
                            if (i != temp.Length - 1)
                            {
                                sb.Append(":");
                            }
                        }
                    }
                    temp = sb.ToString();
                }
                st_bluetooth_result.Text = temp;
                if (st_bluetooth_autocopy.Checked)
                {
                    if (!string.IsNullOrEmpty(temp))
                    {
                        Clipboard.SetDataObject(temp);
                    }
                }
            }
            catch (Exception ee)
            {
                MsgShow.Error(ee.Message);
            }

        }
        /// <summary>
        /// 点击蓝牙地址时，直接全选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void common_MouseDown(object sender, MouseEventArgs e)
        {
            var tb = sender as TextBox;
            if (!string.IsNullOrEmpty(tb.Text))
            {
                tb.SelectAll();
            }
        }

    }
}
